﻿using ETA.DtoMappings;
using ETA.Entity;
using ETA.IService;
using Ninject;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ETA.UnitTest
{
    [TestFixture]
    public class FlowLogServiceTest
    {
        private static IFlowLogService _IFlowLogService { set; get; }
        private static IRegistrationMainFormService _IRegistrationMainFormService { set; get; }
        private static IUserService _IUserService { set; get; }
        private static IFlowStepService _IFlowStepService { set; get; }

        [SetUp]
        public void Init()
        {
            DtoMapConfig.InitMap();
            IKernel kernel = new StandardKernel(new NinjectModuleBuild());
            _IFlowLogService = kernel.Get<IFlowLogService>();
            _IRegistrationMainFormService = kernel.Get<IRegistrationMainFormService>();
            _IUserService = kernel.Get<IUserService>();
            _IFlowStepService = kernel.Get<IFlowStepService>();
        }

        [Test]
        public void AddFlowLogTest()
        {
            var flowStep = new FlowStep();
            var flowStepResponse = _IFlowStepService.QueryFlowStepList(new QueryFlowStepRequest
            {
                FlowStep = new FlowStep
                {
                    FlowIndex = 1
                }
            });
            if (flowStepResponse.Result.IsSuccess)
            {
                flowStep = flowStepResponse.FlowSteps.FirstOrDefault();
            }


            var reqUser = new QueryUserRequest
            {
                User = new User
                {
                    LoginName = "skyforce2008"
                }
            };

            var response = _IUserService.QueryUser(reqUser);


            var log = new FlowLog();
            log.FlowLogId = Guid.NewGuid() + "";
            var mainForm = response.Users.First().RegistrationMainForms.First();
            log.RegistrationMainForm = mainForm;
            log.FlowStepInfo = flowStep;
            log.SourceEnum = DomainEnum.SourceEnum.安卓客户端;
            log.FlowLogStateEnum = DomainEnum.FlowLogStateEnum.被拒绝;
            var createLogReq = new CreateFlowLogRequest
            {
                FlowLog = log
            };
            var res = _IFlowLogService.CreateFlowLog(createLogReq);
            Assert.True(res.Result.IsSuccess);
        }

        [Test]
        public void QueryLogTest()
        {
            int count = 0;
            var response = _IFlowLogService.QueryFlowLog(new QueryFlowLogRequest
            {
                FlowLog = new FlowLog
                {
                    FlowStepInfo = new FlowStep {
                         FlowIndex =1
                    }
                },
                Page = 0,
                PageSize = 20
            }, out count);
            Assert.True(count == 1);
        }
    }
}
